package com.hql.handicraft_display_system.admin.controller;


import com.hql.handicraft_display_system.admin.entity.Crafts;
import com.hql.handicraft_display_system.admin.entity.vo.CraftsVO;
import com.hql.handicraft_display_system.admin.result.PageModel;
import com.hql.handicraft_display_system.admin.result.R;
import com.hql.handicraft_display_system.admin.service.CraftsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hql
 * @since 2022-01-08
 */
@RestController
@RequestMapping("/crafts")
@CrossOrigin
public class CraftsController {

    @Autowired
    private CraftsService craftsService;

    @GetMapping("/list/{page}/{limit}")
    public R list(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit,
            @RequestParam(value = "keyword", required = false) String keyword
    ) {
        PageModel<CraftsVO> pageModel = craftsService.listByPage(page, limit, keyword);
        return R.ok().data("pageModel", pageModel);
    }

    @GetMapping("/status/{id}/{status}")
    public R changeStatus(
            @PathVariable("id") Integer id,
            @PathVariable("status") Integer status
    ) {
        craftsService.changeStatus(id, status);
        return R.ok();
    }

    @PostMapping("/addOrUpdate")
    public R addOrUpdate(@RequestBody Crafts crafts) {
        craftsService.addOrUpdate(crafts);
        return R.ok();
    }
}

